import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }

        int[] maxVal = new int[n + 1];
        int[] maxCnt = new int[n + 1];
        int[] second = new int[n + 1];

        maxVal[1] = a[1];
        maxCnt[1] = 1;
        second[1] = Integer.MIN_VALUE; // 没有次大

        for (int i = 2; i <= n; i++) {
            if (a[i] > maxVal[i - 1]) {
                second[i] = maxVal[i - 1];
                maxVal[i] = a[i];
                maxCnt[i] = 1;
            } else if (a[i] == maxVal[i - 1]) {
                maxVal[i] = maxVal[i - 1];
                maxCnt[i] = maxCnt[i - 1] + 1;
                second[i] = second[i - 1];
            } else {
                maxVal[i] = maxVal[i - 1];
                maxCnt[i] = maxCnt[i - 1];
                second[i] = Math.max(second[i - 1], a[i]);
            }
        }

        int q = in.nextInt();
        while (q-- > 0) {
            int x = in.nextInt();
            if (maxCnt[x] >= 2) {
                System.out.println(maxVal[x]);
            } else {
                System.out.println(second[x]);
            }
        }
    }
}
